define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'enterprise/index' + location.search,
                    add_url: 'enterprise/add',
                    edit_url: 'enterprise/edit',
                    del_url: 'enterprise/del',
                    multi_url: 'enterprise/multi',
                    import_url: 'enterprise/import',
                    table: 'enterprise',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id')},
                        {field: 'name', title: __('Name'), operate: 'LIKE'},
                        {field: 'number', title: __('Number'), operate: 'LIKE'},
                        {field: 'econ_kind', title: __('Econ_kind'), operate: 'LIKE'},
                        {field: 'addresses', title: __('Addresses'), operate: 'LIKE'},
                        {field: 'reg_no', title: __('Reg_no'), operate: 'LIKE'},
                        {field: 'term_start', title: __('Term_start'), operate: 'LIKE'},
                        {field: 'term_end', title: __('Term_end'), operate: 'LIKE'},
                        {field: 'belong_org', title: __('Belong_org'), operate: 'LIKE'},
                        {field: 'oper_name', title: __('Oper_name'), operate: 'LIKE'},
                        {field: 'start_date', title: __('Start_date'), operate: 'LIKE'},
                        {field: 'end_date', title: __('End_date'), operate: 'LIKE'},
                        {field: 'status', title: __('Status'), operate: 'LIKE', formatter: Table.api.formatter.status},
                        {field: 'org_no', title: __('Org_no'), operate: 'LIKE'},
                        {field: 'credit_no', title: __('Credit_no'), operate: 'LIKE'},
                        {field: 'province', title: __('Province'), operate: 'LIKE'},
                        {field: 'brances_name', title: __('Brances_name'), operate: 'LIKE'},
                        {field: 'egist_capi_new', title: __('Egist_capi_new'), operate: 'LIKE'},
                        {field: 'currency_unit', title: __('Currency_unit'), operate: 'LIKE'},
                        {field: 'createtime', title: __('Createtime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {field: 'updatetime', title: __('Updatetime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});